package com.yuerenjf.yuerenjinfu.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.yuerenjf.yuerenjinfu.R;
import com.yuerenjf.yuerenjinfu.bean.OwnZichanBean;
import com.yuerenjf.yuerenjinfu.utils.MyDisplayImageOptions;

import java.util.List;

/**
 * Created by Administrator on 2017/6/13 0013.
 */

public class AdapterOwnSecond extends BaseAdapter{
    Activity mActivity;
    private List<OwnZichanBean> beanList;
    public AdapterOwnSecond(Activity mActivity, List<OwnZichanBean> beanList){
        this.mActivity=mActivity;
        this.beanList=beanList;
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View convertView=null;ViewHolder viewHolder;
        if(convertView==null){

            convertView= LayoutInflater.from(mActivity).inflate(R.layout.item_own_second,null);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) convertView.getTag();
        }

        OwnZichanBean bean=beanList.get(i);

        if(null==bean.getText()){
            viewHolder.imageView.setVisibility(View.GONE);
            viewHolder.titleText.setVisibility(View.GONE);
            viewHolder.statusImage.setVisibility(View.GONE);
        }else{
            viewHolder.imageView.setVisibility(View.VISIBLE);
            viewHolder.titleText.setVisibility(View.VISIBLE);
            ImageLoader.getInstance().displayImage(bean.getImage(), viewHolder.imageView,MyDisplayImageOptions.getInstance(0));
//            viewHolder.imageView.setImageResource(bean.getImageRes());
            viewHolder.titleText.setText(bean.getText());
            if(bean.getText().equals("优惠券")){
                viewHolder.statusImage.setVisibility(View.VISIBLE);
                viewHolder.statusImage.setText(bean.getNumber());
            }else{
                viewHolder.statusImage.setVisibility(View.INVISIBLE);
            }
        }

        return convertView;
    }

    class ViewHolder{
        ImageView imageView;
        TextView titleText;
        TextView statusImage;
        public ViewHolder(View view) {
            imageView= (ImageView) view.findViewById(R.id.item_own_zichan_icon_image);
            titleText= (TextView) view.findViewById(R.id.item_own_zichan_title_text);
            statusImage= (TextView) view.findViewById(R.id.item_own_zichan_status_image);
        }

    }
}
